package com.tsystems.tuni.sportplanet.entity;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlTransient;

/**
 * Team Entity.
 * 
 * @author Yuriy Eremin
 * 
 */
@Entity
@Table(name = "team", catalog = "sportsplanet")
public class Team implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer teamId;
	private Sport sport;
	private Company company;
	private int playerCount;
	private int price;
	private String sponsor;
	private Set<Result> results = new HashSet<Result>(0);
	private Set<Player> players = new HashSet<Player>(0);

	public Team() {
	}

	public Team(Integer id, Sport sport, Company company, int playerCount, int price) {
		this.teamId = id;
		this.sport = sport;
		this.company = company;
		this.playerCount = playerCount;
		this.price = price;
	}

	public Team(Sport sport, Company company, int playerCount, int price) {
		this.sport = sport;
		this.company = company;
		this.playerCount = playerCount;
		this.price = price;
	}
	
	public Team(Sport sport, Company company, int playerCount, int price, String sponsor) {
		this.sport = sport;
		this.company = company;
		this.playerCount = playerCount;
		this.price = price;
		this.sponsor = sponsor;
	}

	public Team(Sport sport, Company company, int playerCount, int price,
			Set<Result> results, Set<Player> players) {
		this.sport = sport;
		this.company = company;
		this.playerCount = playerCount;
		this.price = price;
		this.results = results;
		this.players = players;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "team_id", unique = true, nullable = false)
	public Integer getTeamId() {
		return this.teamId;
	}

	public void setTeamId(Integer teamId) {
		this.teamId = teamId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SPORT_sport_id", nullable = false)
	@XmlTransient
	public Sport getSport() {
		return this.sport;
	}

	public void setSport(Sport sport) {
		this.sport = sport;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "COMPANY_company_id", nullable = false)
	@XmlTransient
	public Company getCompany() {
		return this.company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	@Column(name = "playerCount", nullable = false)
	public int getPlayerCount() {
		return this.playerCount;
	}

	public void setPlayerCount(int playerCount) {
		this.playerCount = playerCount;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "team")
	@XmlTransient
	public Set<Result> getResults() {
		return this.results;
	}

	public void setResults(Set<Result> results) {
		this.results = results;
	}
	
	@Column(name = "price", nullable = false)
	public int getPrice() {
		return price;
	}

	public void setPrice(int price) {
		this.price = price;
	}
	
	@Column(name = "sponsor")
	public String getSponsor() {
		return sponsor;
	}

	public void setSponsor(String sponsor) {
		this.sponsor = sponsor;
	}
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "team")
	@XmlTransient
	public Set<Player> getPlayers() {
		return this.players;
	}

	public void setPlayers(Set<Player> players) {
		this.players = players;
	}

	@Override
	public String toString() {
		return company.getCompanyName();
	}

}
